package hlhj.fhp.supreme.adapters

import android.content.Context
import android.util.SparseArray
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import android.widget.TextView
import fhp.hlhj.giantfold.utils.LogUtil
import hlhj.fhp.supreme.R
import hlhj.fhp.supreme.javabean.CommentBean
import java.util.ArrayList

/**
 * Created by Administrator on 2018\3\13 0013.
 */
class HotListAdp(private val datas:ArrayList<CommentBean.DataBean.HotBean.SonBeanX>, private val context:Context) :BaseAdapter(){
    override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View {
        var convertView=convertView
        if (convertView==null){
            convertView=LayoutInflater.from(context).inflate(R.layout.talk_item, null)
        }
        val tvName = convertView?.findViewOften<TextView>(R.id.itemName)
        val itemInfo = convertView?.findViewOften<TextView>(R.id.itemInfo)
        tvName?.text=datas[position].full_name
        itemInfo?.text=datas[position].content
        LogUtil.log("经过几次")
        return convertView!!
    }

    override fun getItem(position: Int): Any {
        return datas[position]
    }

    override fun getItemId(position: Int): Long {
        return position.toLong()
    }

    override fun getCount(): Int {
        LogUtil.log("大小${datas.size}")
        return datas.size
    }

    fun <T : View> View.findViewOften(viewId: Int): T {
        var viewHolder: SparseArray<View> = tag as? SparseArray<View> ?: SparseArray()
        tag = viewHolder
        var childView: View? = viewHolder.get(viewId)
        if (null == childView) {
            childView = findViewById(viewId)
            viewHolder.put(viewId, childView)
        }
        return childView as T
    }
}